/******************************************************************************* 
 *  Copyright 2007 Amazon Technologies, Inc.  
 *  Licensed under the Apache License, Version 2.0 (the "License"); 
 *  
 *  You may not use this file except in compliance with the License. 
 *  You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
 *  This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
 *  CONDITIONS OF ANY KIND, either express or implied. See the License for the 
 *  specific language governing permissions and limitations under the License.
 * ***************************************************************************** 
 *    __  _    _  ___ 
 *   (  )( \/\/ )/ __)
 *   /__\ \    / \__ \
 *  (_)(_) \/\/  (___/
 * 
 *  Amazon ECS CSharp Library
 *  API Version: 2007-07-16
 *  Generated: Thu Aug 02 10:15:38 PDT 2007 
 * 
 */

using System;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Text;


namespace Amazon.ECS.Model
{
    [XmlTypeAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16")]
    [XmlRootAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16", IsNullable = false)]
    public class ItemDimensions
    {
    
        private  DecimalWithUnits heightField;
        private  DecimalWithUnits lengthField;
        private  DecimalWithUnits weightField;
        private  DecimalWithUnits widthField;

        /// <summary>
        /// Gets and sets the Height property.
        /// </summary>
        [XmlElementAttribute(ElementName = "Height")]
        public DecimalWithUnits Height
        {
            get { return this.heightField ; }
            set { this.heightField = value; }
        }



        /// <summary>
        /// Sets the Height property
        /// </summary>
        /// <param name="height">Height property</param>
        /// <returns>this instance</returns>
        public ItemDimensions WithHeight(DecimalWithUnits height)
        {
            this.heightField = height;
            return this;
        }



        /// <summary>
        /// Checks if Height property is set
        /// </summary>
        /// <returns>true if Height property is set</returns>
        public Boolean IsSetHeight()
        {
            return this.heightField != null;
        }




        /// <summary>
        /// Gets and sets the Length property.
        /// </summary>
        [XmlElementAttribute(ElementName = "Length")]
        public DecimalWithUnits Length
        {
            get { return this.lengthField ; }
            set { this.lengthField = value; }
        }



        /// <summary>
        /// Sets the Length property
        /// </summary>
        /// <param name="length">Length property</param>
        /// <returns>this instance</returns>
        public ItemDimensions WithLength(DecimalWithUnits length)
        {
            this.lengthField = length;
            return this;
        }



        /// <summary>
        /// Checks if Length property is set
        /// </summary>
        /// <returns>true if Length property is set</returns>
        public Boolean IsSetLength()
        {
            return this.lengthField != null;
        }




        /// <summary>
        /// Gets and sets the Weight property.
        /// </summary>
        [XmlElementAttribute(ElementName = "Weight")]
        public DecimalWithUnits Weight
        {
            get { return this.weightField ; }
            set { this.weightField = value; }
        }



        /// <summary>
        /// Sets the Weight property
        /// </summary>
        /// <param name="weight">Weight property</param>
        /// <returns>this instance</returns>
        public ItemDimensions WithWeight(DecimalWithUnits weight)
        {
            this.weightField = weight;
            return this;
        }



        /// <summary>
        /// Checks if Weight property is set
        /// </summary>
        /// <returns>true if Weight property is set</returns>
        public Boolean IsSetWeight()
        {
            return this.weightField != null;
        }




        /// <summary>
        /// Gets and sets the Width property.
        /// </summary>
        [XmlElementAttribute(ElementName = "Width")]
        public DecimalWithUnits Width
        {
            get { return this.widthField ; }
            set { this.widthField = value; }
        }



        /// <summary>
        /// Sets the Width property
        /// </summary>
        /// <param name="width">Width property</param>
        /// <returns>this instance</returns>
        public ItemDimensions WithWidth(DecimalWithUnits width)
        {
            this.widthField = width;
            return this;
        }



        /// <summary>
        /// Checks if Width property is set
        /// </summary>
        /// <returns>true if Width property is set</returns>
        public Boolean IsSetWidth()
        {
            return this.widthField != null;
        }






        /// <summary>
        /// XML fragment representation of this object
        /// </summary>
        /// <returns>XML fragment for this object.</returns>
        /// <remarks>
        /// Name for outer tag expected to be set by calling method. 
        /// This fragment returns inner properties representation only
        /// </remarks>


        protected internal String ToXMLFragment() {
            StringBuilder xml = new StringBuilder();
            if (IsSetHeight()) {
                DecimalWithUnits  height = this.Height;
                xml.Append("<Height Units=" + "\"" +  EscapeXML(height.Units)  + "\"" +  ">");
                xml.Append(height.Value);
                xml.Append("</Height>");
            } 
            if (IsSetLength()) {
                DecimalWithUnits  length = this.Length;
                xml.Append("<Length Units=" + "\"" +  EscapeXML(length.Units)  + "\"" +  ">");
                xml.Append(length.Value);
                xml.Append("</Length>");
            } 
            if (IsSetWeight()) {
                DecimalWithUnits  weight = this.Weight;
                xml.Append("<Weight Units=" + "\"" +  EscapeXML(weight.Units)  + "\"" +  ">");
                xml.Append(weight.Value);
                xml.Append("</Weight>");
            } 
            if (IsSetWidth()) {
                DecimalWithUnits  width = this.Width;
                xml.Append("<Width Units=" + "\"" +  EscapeXML(width.Units)  + "\"" +  ">");
                xml.Append(width.Value);
                xml.Append("</Width>");
            } 
            return xml.ToString();
        }

        /**
         * 
         * Escape XML special characters
         */
        private String EscapeXML(String str) {
            StringBuilder sb = new StringBuilder();
            foreach (Char c in str)
            {
                switch (c) {
                case '&':
                    sb.Append("&amp;");
                    break;
                case '<':
                    sb.Append("&lt;");
                    break;
                case '>':
                    sb.Append("&gt;");
                    break;
                case '\'':
                    sb.Append("&#039;");
                    break;
                case '"':
                    sb.Append("&quot;");
                    break;
                default:
                    sb.Append(c);
                    break;
                }
            }
            return sb.ToString();
        }




    }

}